<template>
  <view class="page_root" data-page-name="任务详情" data-page-identification="i_iawj8j2405">
    <!-- UNI_APP_EXEGESIS_START NAVIGATION_TEMPLATE UNI_APP_EXEGESIS_END -->
    <!-- begin vid_pon2nmqufo 自定义模板_bfu381a654 -->
    <u-mask :show="loadingShow" @click="show = false">
      <view style="height: 100px; width: 100px;position: absolute; top: 50%; left: 50%;transform: translate(-50%, -50%);">
        <u-loading :color="'red'" mode="semicircle" textSize="50" :show="loadingShow.value" size="100"></u-loading>
        <view v-if="loadingShow" style="color: #fff;">正在提交....</view>
      </view>
    </u-mask>
    <view class="container">
      <view class="content" :style="{ height: isDisabled ? '100%' : '92%' }">
        <view class="item">
          <view class="title">
            <span v-if="taskDetail.mark" class="mark">{{ taskDetail.mark }}</span>
            {{ taskDetail.taskName ||taskDetail.actionTaskName}}
          </view>
          <view class="article">
            <view class="class1">
              <view style="display: flex;">
                <view class="class2 mr10">{{ taskDetail.taskStatus }}</view>
                <view class="first mr10" v-if="taskDetail.mark === '初验'">初验</view>
                <view class="lcb mr10" v-if="taskDetail.mark === '里程碑'">里程碑</view>
                <view class="finally mr10" v-if="taskDetail.mark === '终验'">终验</view>
                <view class="gjlj mr10" v-if="taskDetail.critialPath === '关键路径'">关键路径</view>
                <view class="class2" v-if="taskDetail.instanceId" style="color: #FEA631;">审批中</view>
              </view>
              <view class="class3"><svg width="14px" height="14px" viewBox="0 0 14 14" version="1.1"
                  xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
                  <title></title>
                  <g id="任务列表" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                    <g id="任务详情-可编辑备份-6" transform="translate(-296, -146)" fill-rule="nonzero">
                      <g id="编组-14备份-2" transform="translate(31, 143)">
                        <g id="编组-13" transform="translate(258, 0)">
                          <g id="编组-9备份-5" transform="translate(7, 1)">
                            <g id="编组-6" transform="translate(0, 2)">
                              <rect id="矩形" fill="#000000" opacity="0" x="0" y="0" width="14" height="14"></rect>
                              <path
                                d="M9.40794574,10.9544574 L10.0862403,10.9544574 L10.0862403,10.2083333 L9.47577519,9.59786822 L7.91569767,9.59786822 L8.72965116,8.24127906 L10.0184109,8.24127906 L11.375,9.59786822 L11.375,12.3110465 L7.98352714,12.3110465 L9.40794574,10.9544574 L9.40794574,10.9544574 Z M4.65988372,10.9544574 L6.01647286,12.3110465 L2.625,12.3110465 L2.625,9.59786822 L2.69282946,9.59786822 L4.0494186,8.24127906 L5.3381783,8.24127906 L6.15213179,9.59786822 L4.59205426,9.59786822 L3.98158914,10.2083333 L3.98158914,10.9544574 L4.65988372,10.9544574 L4.65988372,10.9544574 Z M10.0862403,4.51065892 C10.0862403,6.20639536 8.72965116,7.5629845 7.03391472,7.5629845 C5.33817828,7.5629845 3.98158914,6.20639534 3.98158914,4.51065892 C3.98158914,2.8149225 5.3381783,1.45833334 7.03391472,1.45833334 C8.72965115,1.45833334 10.0862403,2.81492248 10.0862403,4.51065892 L10.0862403,4.51065892 Z M8.72965116,4.51065892 C8.72965116,3.56104651 7.98352714,2.81492248 7.03391472,2.81492248 C6.08430231,2.81492248 5.3381783,3.56104651 5.3381783,4.51065892 C5.3381783,5.46027133 6.08430233,6.20639534 7.03391472,6.20639534 C7.98352712,6.20639534 8.72965116,5.46027132 8.72965116,4.51065892 L8.72965116,4.51065892 Z M6.01647286,8.24127906 L8.05135658,8.24127906 L7.37306202,9.59786822 L8.05135658,11.6327519 L7.03391472,12.6501938 L6.01647286,11.6327519 L6.69476744,9.59786822 L6.01647286,8.24127906 L6.01647286,8.24127906 Z"
                                id="形状" fill="#8C8C8C"></path>
                            </g>
                          </g>
                        </g>
                      </g>
                    </g>
                  </g>
                </svg>{{ taskDetail.taskOwner }}</view>
            </view>
            <u-row class="row">
              <u-col :span="3" class="title1">项目名称:</u-col>
              <u-col :span="9" class="value1" style="margin-left: -36rpx;">{{ taskDetail.projectName }}</u-col>
            </u-row>
            <u-row class="row" v-if="!isActionTask">
              <u-col :span="3" class="title1">项目阶段:</u-col>
              <u-col :span="9" class="value1" style="margin-left: -36rpx;">{{ taskDetail.milepostName }}</u-col>
            </u-row>
            <u-row class="row no-padding">
              <u-col :span="6">
                <u-row>
                  <u-col :span="5" class="title1">计划开始:</u-col>
                  <u-col :span="7" class="value1" style="padding: 0;">{{ taskDetail.startTime }}</u-col>
                </u-row>
              </u-col>
              <u-col :span="6">
                <u-row>
                  <u-col :span="5" class="title1">实际开始:</u-col>
                  <u-col :span="7" class="value1" style="padding: 0;">{{ taskDetail.actualStartTime }}</u-col>
                </u-row>
              </u-col>
            </u-row>
            <u-row class="row no-padding">
              <u-col :span="6">
                <u-row>
                  <u-col :span="5" class="title1">计划完成:</u-col>
                  <u-col :span="7" class="value1" style="padding: 0;">{{ taskDetail.endTime }}</u-col>
                </u-row>
              </u-col>
              <u-col :span="6">
                <u-row>
                  <u-col :span="5" class="title1">实际完成:</u-col>
                  <u-col :span="7" class="value1" style="padding: 0;">{{ taskDetail.taskFinishTime }}</u-col>
                </u-row>
              </u-col>
            </u-row>
            <view class="label-wrapper" v-if="taskDetail.labelList">
              <template v-for="(label, index) in taskDetail.labelList" :key="index">
                <view class="label" v-if="hasTime(label)" :class="activeClass(label)">
                  {{ label }}
                </view>
              </template>
            </view>
            <u-form :model="taskDetail" ref="recordForm" >
              <u-form-item v-if="!isActionTask" label-position="top" label="甲方工作事项：" prop="taskRemarks" :border-bottom="false">
                <u-input disabled type="textarea" :height="150" border="true" placeholder=""
                  v-model:modelValue="taskDetail.taskRemarks"></u-input>
              </u-form-item>
              <u-form-item v-if="!isActionTask" label-position="top" label="最新风险和解决方案：" :border-bottom="false">
                <u-input disabled type="textarea" :height="150" border="true" placeholder=""
                  :modelValue="taskDetail.riskAndSolution"></u-input>
              </u-form-item>
              <u-form-item v-if="!isActionTask" label-position="top" label="备注：" prop="description" :border-bottom="false">
                <u-input disabled type="textarea" :height="150" border="true" placeholder=""
                  v-model:modelValue="taskDetail.description"></u-input>
              </u-form-item>
              <u-form-item v-if="!isActionTask" label-position="top" label="完成标准：" :border-bottom="false">
                <u-checkbox-group :options="finishStandardList" v-model:modelValue="formState.checkList1">
                  <u-checkbox v-for="(item, index) in finishStandardList" :key="index" v-model="item.selected"
                    :disabled="isDisabled" :name="item.content">{{ item.content }} </u-checkbox>
                </u-checkbox-group>
              </u-form-item>
              <u-form-item  label-position="top" label="完成标准：" :border-bottom="false">
                <u-input disabled type="textarea" :height="150" border="true" placeholder=""
                  v-model:modelValue="taskDetail.finishStandard"></u-input>
              </u-form-item>
              <u-form-item v-if="!isActionTask" label-position="top" label="SOP:" :border-bottom="false">
                <u-checkbox-group :options="sopList" v-model:modelValue="formState.sopCheck" v-if="sopList.length > 0">
                  <u-checkbox v-model="item.selected" :disabled="isDisabled"
                    v-for="(item, index) in sopList[0].contentList" :key="index" :name="item.msg">{{ item.msg }}
                  </u-checkbox>
                </u-checkbox-group>
              </u-form-item>
              <view class="divider"></view>
              <u-form-item label-position="top" label="图片：" prop="attachment" :border-bottom="false">
                <u-upload width="106px" height="106px" class="vid_rg51oa99zm" :action="vid_rg51oa99zm_props.action"
                  :uploadFile="vid_rg51oa99zm_props.uploadFile"
                  :isShowFormatContent="vid_rg51oa99zm_props.isShowFormatContent"
                  :listType="vid_rg51oa99zm_props.listType" :required="vid_rg51oa99zm_props.required"
                  v-model:fileList="taskDetail.attachment" :deletable="uploadDisabled"
                  maximumFileSize="vid_rg51oa99zm_props.maximumFileSize"
                  @uploadFailed="handle_vid_rg51oa99zm_uploadFailed"
                  @uploadSuccess="handle_vid_rg51oa99zm_uploadSuccess"
                  @removeSuccess="handle_vid_rg51oa99zm_uploadSuccess">
                </u-upload>
              </u-form-item>
              <view class="divider"></view>

              <u-form-item v-if="!isActionTask" class="assessor" label-position="top" label="审核标准及注意事项：" :border-bottom="false">
                <view v-for="(item, index) in taskDetail.assessorStandardList" :key="index">
                  {{ item.content }}
                </view>
              </u-form-item>
            </u-form>
          </view>
        </view>
      </view>
      <view class="bottom-btn" v-if="!isActionTask">
        <u-button :disabled="completeDisabled" block type="primary" class="bc-btn" v-if="!isDisabled"
          @click="handleSubmitSop">保存</u-button>
        <u-button :disabled="completeDisabled" block type="primary" class="wc-btn" v-if="!isDisabled"
          @click="handleComplete">完成</u-button>
      </view>
      <u-button block type="primary" class="complete"
        v-if="!isDisabled && (!taskDetail.taskExamStatus || taskDetail.taskExamStatus === '未通过') && taskDetail.projectTemplate&&!isActionTask"
        @click="handleStart">开始</u-button>
      <u-button block type="primary" class="complete"
        v-if="!isDisabled && (!taskDetail.taskExamStatus || taskDetail.taskExamStatus === '未通过')&&isActionTask"
        @click="handleStart">开始</u-button>
      <!-- 冯腾飞加 -->
      <u-button block type="primary" class="complete"
        v-if="!isDisabled && isActionTask && taskDetail.taskExamStatus === '已通过'"
        @click="handleComplete">完成</u-button>
      <!-- 冯腾飞加 -->
    </view>
    <u-toast ref="toast" class="al-toast"></u-toast>
    <!-- end vid_pon2nmqufo 自定义模板_bfu381a654 -->
  </view>
</template>
<script setup>

import {
  ref, reactive, toRaw, markRaw,
  watch, computed,
  onBeforeMount, onMounted, onBeforeUnmount, onUnmounted, onActivated, onDeactivated, getCurrentInstance
} from "vue";
import { useRoute } from 'vue-router';
const route = useRoute();
import { get, post, put, del, request, requestWithHeaders } from '@/utils/http/Axios';
import { cloneDeep, localGet, traversalTreeStructure, set, checkCaseCondition, throttle, merge, debounce, getGridStyle, getCellRenderAble, formulaStrategy } from '@/utils/index';
import { isEqual, isNullOrEmpty, isEmptyArr, isArray, isEmpty, isNullOrUnDef, isContained } from '@/utils/is';
import { CovertOptions, getChartsDataSourceConvert } from '@/utils/chart';
import { propertyFormatByNumber, propertyFormatByPercentage, propertyFormatByDate } from '@/utils/format';
import { FormFormat } from '@/utils/formFormat'
import { customAddWaterMarkFunc, generateWaterMarkText } from '@/utils/addWaterMark';
import dayjs from 'dayjs';
import hashSum from 'hash-sum';
import { handleRedirect, } from '@/utils/common';
import { onPullDownRefresh, onLoad, onReady, onShow, onHide, onPageScroll, onUnload } from '@dcloudio/uni-app';
/*** UNI_APP_EXEGESIS ***
import { handleRedirect, permission, parseJson } from '@/utils/common';
import { onPullDownRefresh, onLoad, onReady, onShow, onHide, onPageScroll, onUnload } from '@dcloudio/uni-app';
import { BroadcastMessage } from '@/utils/BroadcastMessage';
import { sendToken } from "@/hooks/useIframeToken";
*** UNI_APP_EXEGESIS ***/


// ---------------------------- 属性定义 ----------------------------
const sourceId = "page3000000252"

// 是否显示菜单按钮
const isMenuIconShow = false;
// NAVIGATION_MENU
const handleShowNavigation = () => { };

let isProcessState = ref(false);


const setTimeOutList = [];


const vid_pon2nmqufo_props = reactive({
  code: "    <view class=\"container\">\n      <view class=\"content\" :style=\"{ height: isDisabled ? '100%' : '92%' }\">\n        <view class=\"item\">\n          <view class=\"title\">\n            <!-- <span v-if=\"taskDetail.mark\" class=\"mark\">{{ taskDetail.mark }}</span> -->\n            {{ taskDetail.taskName }}\n          </view>\n          <view class=\"article\">\n            <view class=\"class1\">\n              <view style=\"display: flex;\">\n                <view class=\"class2 mr10\">{{ taskDetail.taskStatus }}</view>\n                                <view class=\"first mr10\" v-if=\"taskDetail.mark==='初验' \">初验</view>\n                  <view class=\"lcb mr10\" v-if=\"taskDetail.mark==='里程碑' \">里程碑</view>\n                  <view class=\"finally mr10\"  v-if=\"taskDetail.mark==='终验' \">终验</view>\n                  <view class=\"gjlj mr10\" v-if=\"taskDetail.critialPath==='关键路径' \">关键路径</view>\n                <view class=\"class2\" v-if=\"taskDetail.instanceId\" style=\"color: #FEA631;\">审批中</view>\n              </view>\n              <view class=\"class3\"><svg width=\"14px\" height=\"14px\" viewBox=\"0 0 14 14\" version=\"1.1\"\n                  xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                  <title></title>\n                  <g id=\"任务列表\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"任务详情-可编辑备份-6\" transform=\"translate(-296, -146)\" fill-rule=\"nonzero\">\n                      <g id=\"编组-14备份-2\" transform=\"translate(31, 143)\">\n                        <g id=\"编组-13\" transform=\"translate(258, 0)\">\n                          <g id=\"编组-9备份-5\" transform=\"translate(7, 1)\">\n                            <g id=\"编组-6\" transform=\"translate(0, 2)\">\n                              <rect id=\"矩形\" fill=\"#000000\" opacity=\"0\" x=\"0\" y=\"0\" width=\"14\" height=\"14\"></rect>\n                              <path\n                                d=\"M9.40794574,10.9544574 L10.0862403,10.9544574 L10.0862403,10.2083333 L9.47577519,9.59786822 L7.91569767,9.59786822 L8.72965116,8.24127906 L10.0184109,8.24127906 L11.375,9.59786822 L11.375,12.3110465 L7.98352714,12.3110465 L9.40794574,10.9544574 L9.40794574,10.9544574 Z M4.65988372,10.9544574 L6.01647286,12.3110465 L2.625,12.3110465 L2.625,9.59786822 L2.69282946,9.59786822 L4.0494186,8.24127906 L5.3381783,8.24127906 L6.15213179,9.59786822 L4.59205426,9.59786822 L3.98158914,10.2083333 L3.98158914,10.9544574 L4.65988372,10.9544574 L4.65988372,10.9544574 Z M10.0862403,4.51065892 C10.0862403,6.20639536 8.72965116,7.5629845 7.03391472,7.5629845 C5.33817828,7.5629845 3.98158914,6.20639534 3.98158914,4.51065892 C3.98158914,2.8149225 5.3381783,1.45833334 7.03391472,1.45833334 C8.72965115,1.45833334 10.0862403,2.81492248 10.0862403,4.51065892 L10.0862403,4.51065892 Z M8.72965116,4.51065892 C8.72965116,3.56104651 7.98352714,2.81492248 7.03391472,2.81492248 C6.08430231,2.81492248 5.3381783,3.56104651 5.3381783,4.51065892 C5.3381783,5.46027133 6.08430233,6.20639534 7.03391472,6.20639534 C7.98352712,6.20639534 8.72965116,5.46027132 8.72965116,4.51065892 L8.72965116,4.51065892 Z M6.01647286,8.24127906 L8.05135658,8.24127906 L7.37306202,9.59786822 L8.05135658,11.6327519 L7.03391472,12.6501938 L6.01647286,11.6327519 L6.69476744,9.59786822 L6.01647286,8.24127906 L6.01647286,8.24127906 Z\"\n                                id=\"形状\" fill=\"#8C8C8C\"></path>\n                            </g>\n                          </g>\n                        </g>\n                      </g>\n                    </g>\n                  </g>\n                </svg>{{ taskDetail.taskOwner }}</view>\n            </view>\n            <u-row class=\"row\">\n              <u-col :span=\"3\" class=\"title1\">项目名称:</u-col>\n              <u-col :span=\"9\" class=\"value1\" style=\"margin-left: -36rpx;\">{{ taskDetail.projectName }}</u-col>\n            </u-row>\n            <u-row class=\"row\">\n              <u-col :span=\"3\" class=\"title1\">项目阶段:</u-col>\n              <u-col :span=\"9\" class=\"value1\" style=\"margin-left: -36rpx;\">{{ taskDetail.milepostName }}</u-col>\n            </u-row>\n            <u-row class=\"row no-padding\">\n              <u-col :span=\"6\">\n                <u-row>\n                  <u-col :span=\"5\" class=\"title1\">计划开始:</u-col>\n                  <u-col :span=\"7\" class=\"value1\" style=\"padding: 0;\">{{ taskDetail.startTime }}</u-col>\n                </u-row>\n              </u-col>\n              <u-col :span=\"6\">\n                <u-row>\n                  <u-col :span=\"5\" class=\"title1\">实际开始:</u-col>\n                  <u-col :span=\"7\" class=\"value1\" style=\"padding: 0;\">{{ taskDetail.actualStartTime }}</u-col>\n                </u-row>\n              </u-col>\n            </u-row>\n            <u-row class=\"row no-padding\">\n              <u-col :span=\"6\">\n                <u-row>\n                  <u-col :span=\"5\" class=\"title1\">计划完成:</u-col>\n                  <u-col :span=\"7\" class=\"value1\" style=\"padding: 0;\">{{ taskDetail.endTime }}</u-col>\n                </u-row>\n              </u-col>\n              <u-col :span=\"6\">\n                <u-row>\n                  <u-col :span=\"5\" class=\"title1\">实际完成:</u-col>\n                  <u-col :span=\"7\" class=\"value1\" style=\"padding: 0;\">{{ taskDetail.taskFinishTime }}</u-col>\n                </u-row>\n              </u-col>\n            </u-row>\n            <view class=\"label-wrapper\" v-if=\"taskDetail.labelList\">\n              <template v-for=\"(label, index) in taskDetail.labelList\" :key=\"index\">\n                <view class=\"label\" v-if=\"hasTime(label)\" :class=\"activeClass(label)\">\n                  {{ label }}\n                </view>\n              </template>\n            </view>\n            <u-form :model=\"taskDetail\" ref=\"recordForm\">\n              <u-form-item label-position=\"top\" label=\"甲方工作事项：\" prop=\"taskRemarks\" :border-bottom=\"false\">\n                <u-input disabled type=\"textarea\" :height=\"150\" border=\"true\" placeholder=\"\"\n                  v-model:modelValue=\"taskDetail.taskRemarks\"></u-input>\n              </u-form-item>\n              <u-form-item label-position=\"top\" label=\"最新风险和解决方案：\" :border-bottom=\"false\">\n                <u-input disabled type=\"textarea\" :height=\"150\" border=\"true\" placeholder=\"\"\n                  :modelValue=\"taskDetail.riskAndSolution\"></u-input>\n              </u-form-item>\n              <u-form-item label-position=\"top\" label=\"备注：\" prop=\"description\" :border-bottom=\"false\">\n                <u-input disabled type=\"textarea\" :height=\"150\" border=\"true\" placeholder=\"\"\n                  v-model:modelValue=\"taskDetail.description\"></u-input>\n              </u-form-item>\n              <u-form-item label-position=\"top\" label=\"完成标准：\" :border-bottom=\"false\">\n                <u-checkbox-group :options=\"finishStandardList\" v-model:modelValue=\"formState.checkList1\">\n                  <u-checkbox v-for=\"(item, index) in finishStandardList\" :key=\"index\" v-model=\"item.selected\"\n                    :disabled=\"isDisabled\" :name=\"item.content\">{{ item.content }} </u-checkbox>\n                </u-checkbox-group>\n              </u-form-item>\n              <u-form-item label-position=\"top\" label=\"SOP:\" :border-bottom=\"false\">\n                <u-checkbox-group :options=\"sopList\" v-model:modelValue=\"formState.sopCheck\" v-if=\"sopList.length > 0\">\n                  <u-checkbox v-model=\"item.selected\" :disabled=\"isDisabled\"\n                    v-for=\"(item, index) in sopList[0].contentList\" :key=\"index\" :name=\"item.msg\">{{ item.msg }}\n                  </u-checkbox>\n                </u-checkbox-group>\n              </u-form-item>\n              <view class=\"divider\"></view>\n              <u-form-item label-position=\"top\" label=\"图片：\" prop=\"attachment\" :border-bottom=\"false\">\n                <u-upload width=\"106px\" height=\"106px\" class=\"vid_rg51oa99zm\" :action=\"vid_rg51oa99zm_props.action\"\n                  :uploadFile=\"vid_rg51oa99zm_props.uploadFile\"\n                  :isShowFormatContent=\"vid_rg51oa99zm_props.isShowFormatContent\"\n                  :listType=\"vid_rg51oa99zm_props.listType\" :required=\"vid_rg51oa99zm_props.required\"\n                  v-model:fileList=\"taskDetail.attachment\" :deletable=\"uploadDisabled\"\n                  maximumFileSize=\"vid_rg51oa99zm_props.maximumFileSize\"\n                  @uploadFailed=\"handle_vid_rg51oa99zm_uploadFailed\"\n                  @uploadSuccess=\"handle_vid_rg51oa99zm_uploadSuccess\"\n                  @removeSuccess=\"handle_vid_rg51oa99zm_uploadSuccess\">\n                </u-upload>\n              </u-form-item>\n              <view class=\"divider\"></view>\n\n              <u-form-item class=\"assessor\" label-position=\"top\" label=\"审核标准及注意事项：\" :border-bottom=\"false\">\n                <view v-for=\"(item, index) in taskDetail.assessorStandardList\" :key=\"index\">\n                  {{ item.content }}\n                </view>\n              </u-form-item>\n            </u-form>\n          </view>\n        </view>\n      </view>\n      <view class=\"bottom-btn\">\n        <u-button :disabled=\"completeDisabled\" block type=\"primary\" class=\"bc-btn\" v-if=\"!isDisabled\"\n          @click=\"handleSubmitSop\">保存</u-button>\n        <u-button :disabled=\"completeDisabled\" block type=\"primary\" class=\"wc-btn\" v-if=\"!isDisabled\"\n          @click=\"handleComplete\">完成</u-button>\n      </view>\n      <!-- 冯腾飞加 -->\n      <u-button block type=\"primary\" class=\"complete\"\n        v-if=\"!isDisabled && (!taskDetail.taskExamStatus || taskDetail.taskExamStatus === '未通过') && taskDetail.projectTemplate\"\n        @click=\"handleStart\">开始</u-button>\n      <!-- 冯腾飞加 -->\n    </view>\n    <u-toast ref=\"toast\" class=\"al-toast\"></u-toast>",
});



// ============================ 属性定义 ============================

// ---------------------------- 元素数据引用 ----------------------------
// 组件 自定义模板_bfu381a654 ref 的引用
const vid_pon2nmqufo_ref = ref(null);
// 动态key的map
const fieldTypeMap = {};
// 动态key的map
const refMap = { vid_pon2nmqufo_ref };

const showState = reactive({
  vid_pon2nmqufo_visible: true,
})
// ============================ 元素数据引用 ============================

// ---------------------------- 数据 ----------------------------


// ============================ 数据 ============================

// ---------------------------- 方法 ----------------------------
// ---------------------------- 页面数据 ----------------------------


// ============================ 页面数据 ============================

// ---------------------------- 响应 ----------------------------

// ============================ 响应 ============================

// ---------------------------- 函数 ----------------------------

// 自定义函数 返回上一页
const customFunction_goBack_x87dzz2gp2 = (...params) => {
  uni.navigateBack()
}

// ============================ 函数 ============================

// ---------------------------- 页面参数 ----------------------------

const pageParameter_state = reactive({
  'processInstanceId': undefined,
})

// ============================ 页面参数 ============================

// ---------------------------- 组件事件处理方法 ----------------------------


// ============================ 组件事件处理方法 ============================

// ============================ 方法 ============================

// ---------------------------- 生命周期 ----------------------------
/*** UNI_APP_EXEGESIS ***
    // 获取上一层传递的数据
    const workflowChannel = new BroadcastMessage('WORKFLOW');
    workflowChannel.publish({ status: 'Ready' });
    workflowChannel.subscribe((data) => {
      if (data) {
        isProcessState.value = (window.self !== window.parent && data.type === 'hideHeader');
      }
    });
    *** UNI_APP_EXEGESIS ***/


const pageScrollTop = ref(0)

// *** PREVIEW_EXEGESIS ***
onMounted(() => {
  setPageParams(route.query)
  // 设置表单的rule
  try {

  } catch {
    // do nothing
  }
});
// *** PREVIEW_EXEGESIS *** //

/*** UNI_APP_EXEGESIS ***
const routeOption = ref({})
onLoad((option) => {
  routeOption.value = option;
});
onReady(() => {
  setPageParams(routeOption.value)
  // 设置表单的rule
  try{

  }catch{
      // do nothing
  }
});
// 图表刷新标记
const uChartsReshowFlag = ref(false);
onHide(() => { // 页面隐藏后标记置为false(如果不置为false无法触发图表更新)
    uChartsReshowFlag.value = false
})
onShow(() => {
    uChartsReshowFlag.value = true; // 页面激活后,标记置为true

    setPageParams(routeOption.value)
})
onPageScroll(e => {
    pageScrollTop.value = e.scrollTop
});
*** UNI_APP_EXEGESIS ***/

const setPageParams = (routerParam) => {
  const pageParams = [{ "dataType": "STRING", "dependencies": [], "name": "processInstanceId" }];
  const strategyMap = {
    STRING: (param, paramValue) => {
      pageParameter_state[param.name] = paramValue;
    },
    BOOLEAN: (param, paramValue) => {
      if ('true' === (paramValue || '').toLowerCase()) {
        pageParameter_state[param.name] = true
      } else if ('false' === (paramValue || '').toLowerCase()) {
        pageParameter_state[param.name] = false
      } else {
        // TODO: 是否要支持toast
        console.error('参数传入错误！类型不匹配！');
      }
    },
    NUMBER: (param, paramValue) => {
      if (!isNaN(paramValue)) {
        pageParameter_state[param.name] = Number(paramValue);
      } else {
        // TODO: 是否要支持toast
        console.error('参数传入错误！类型不匹配！');
      }
    },
    ARRAY: (param, paramValue) => {
      if (isNullOrUnDef(paramValue) || !paramValue || paramValue === 'undefined') { // default value
        pageParameter_state[param.name] = [];
      } else if (paramValue.trim().startsWith('[') && paramValue.trim().endsWith(']')) {
        try {
          pageParameter_state[param.name] = JSON.parse(decodeURI(paramValue));
        } catch (error) {
          console.error('参数解析失败 ', error);
        }
      } else {
        console.error('参数传入错误！类型不匹配！');
      }
    },
  };
  pageParams.forEach((param) => {
    strategyMap[param.dataType](param, routerParam[param.name])
  });


}

onUnmounted(() => {
  // 销毁定时器
  setTimeOutList.forEach(({ repeat, timer }) => {
    repeat ? clearInterval(timer) : clearTimeout(timer);
  });
});


/*** UNI_APP_EXEGESIS ***
onPullDownRefresh(() => {
  // 下拉刷新
  setTimeout(() => {
      uni.stopPullDownRefresh()
  }, 1000)
})
*** UNI_APP_EXEGESIS ***/

// ============================ 生命周期 ============================

// ---------------------------- 数据关联处理 ----------------------------
// ---------------------------- 组件数据同步 ----------------------------

// ============================ 组件数据同步 ============================
//
// ============================ 数据关联处理 ============================

// ---------------------- 不同组件自定义的处理逻辑 ---------------------

// ====================== 不同组件自定义的处理逻辑 ======================


// ================================定制化逻辑========================================
const formState = reactive({
  checkList1: [],
  sopCheck: []
})

const toast = ref(null);
onMounted(() => {
  let appDiv = document.querySelector('#app')
  if (appDiv) {
    appDiv.style.background = 'linear-gradient(rgb(225, 239, 253) 100%, rgb(255, 255, 255) 0%)';
  }
  let topHeader = document.querySelector('.uni-page-head');
  if (topHeader) topHeader.remove()
  let warpper = document.querySelector('uni-page-wrapper')
  if (warpper) warpper.style.height = '100%';
})

let topHeader = document.querySelector('.uni-page-head');
if (topHeader) topHeader.remove()
const taskDetail = ref({})
const uploadDisabled = ref(false)
const completeDisabled = ref(false)
const isDisabled = computed(() => !!(['审批中', '已完成', '延期完成'].includes(taskDetail.value.taskStatus) || taskDetail.value.instanceId))
// 完成标准
const loadingShow = ref(false)
const finishStandardList = ref([]);
const sopList = ref([]);
const vid_rg51oa99zm_props = reactive({
  name: "file",
  action: "/file-storage/api/v1/file/upload",
  uploadFile: (data) => request({
    url: '/file-storage/api/v1/file/upload',
    method: 'POST',
    responseType: 'blob',
    withCredentials: false,
    data,
    timeout: 360000,
    headers: { "Content-Type": "application/json" },
  }),
  customAddWaterMarkFunc: async (file) => customAddWaterMarkFunc(file, await generateWaterMarkText()),
  isShowFormatContent: false,
  showQrcode: true,
  accept: "image/*",
  multiple: true,
  listType: "picture",
  showUploadList: true,
  required: false,
  qrcodeUrl: undefined,
  token: undefined,
  setTimeOutList: [],
  systemFileList: [],
  isSingle: false,
  isCamera: false,
  addWatermark: false,
  maximumFileSize: "",
})
const isActionTask = ref(false)
const id = ref(false)
const actionTaskId = ref(false)
onMounted(() => {
  let topHeader = document.querySelector('.uni-page-head');
  if (topHeader) {
    let topHeaderBtn = topHeader.querySelector('.uni-page-head-hd');
    if (topHeaderBtn) {
      topHeaderBtn.remove();
    }
  }
  // 获取当前 URL 中问号后的参数部分
  const queryString = window.location.search

// 使用 URLSearchParams 解析参数字符串
const urlParams = new URLSearchParams(queryString)

// 遍历参数并输出
urlParams.forEach((value, key) => {
    console.log(`${key}: ${value}`)
})
    // 获取特定参数的值
     id.value = urlParams.get('id')
     actionTaskId.value = urlParams.get('actionTaskId')
    const type = urlParams.get('type')
    if(type==='行动项任务'){
      isActionTask.value=true
    }else{
      isActionTask.value=false
    }

    getTaskDetail();
})
function getTaskDetail() {
  if(!isActionTask.value){
    get(`/solution-ppm/api/v2/built-in-system-ppm/dashboard/task/${id.value}`).then(({ data }) => {
    if (!data) {
      taskDetail.value = [];
      uploadDisabled.value = !taskDetail.value.taskStatus;
      if (uploadDisabled.value) {
        const a = document.querySelector('.u-list-item.u-add-wrap');
        a && a.remove()
      }
      return;
    }
    taskDetail.value = data;
    taskDetail.value.riskAndSolution = `${data.riskDescription || ''}\n${data.solution || ''}`
    try {
      taskDetail.value.attachment = JSON.parse(data.attachment) || [];
    } catch {
      taskDetail.value.attachment = [];
    }

    if (isDisabled.value) {
      const a = document.querySelector('.u-list-item.u-add-wrap');
      a && a.remove()
    }
    finishStandardList.value = [];
    formState.sopCheck = [];
    // debugger
    if (taskDetail.value.finishStandardList) {
      finishStandardList.value = taskDetail.value.finishStandardList
      taskDetail.value.finishStandardList.forEach(item => {
        console.log(item);
        if (item.selected) {
          formState.checkList1.push(item.content);
        }
      });
    }

    taskDetail.value.sopList = taskDetail.value.sopList
    if (taskDetail.value.sopList) {
      sopList.value = taskDetail.value.sopList
      taskDetail.value.sopList.forEach(item => {
        item.contentList.forEach(contentItem => {
          if (contentItem.selected) {
            formState.sopCheck.push(contentItem.msg);
          }
        });
      });
    }
  }).catch(() => {
    taskDetail.value = {}
  })
  }else{
// 行动项任务
get(`/solution-ppm/api/v2/built-in-system-ppm/dashboard/action_task/${actionTaskId.value}`).then(({data})=>{
  if (!data) {
      taskDetail.value = [];
      uploadDisabled.value = !taskDetail.value.taskStatus;
      if (uploadDisabled.value) {
        const a = document.querySelector('.u-list-item.u-add-wrap');
        a && a.remove()
      }
      return;
    }
  taskDetail.value=data
  try {
      taskDetail.value.attachment = JSON.parse(data.attachment) || [];
    } catch {
      taskDetail.value.attachment = [];
    }
})
  }
  
}
function handleComplete() {
  if(!isActionTask.value){

  completeDisabled.value = true;
  if (!checkAllSelected(finishStandardList.value)) {
    toast.value.show({
      title: '请确认完成标准及SOP全部已实现',
      type: 'error',
    });
    completeDisabled.value = false;
    return;

  }
  if (!checkAllSelected(sopList.value[0].contentList)) {
    completeDisabled.value = true;
    toast.value.show({
      title: '请确认完成标准及SOP全部已实现',
      type: 'error',
    });
    completeDisabled.value = false;
    return;
  }
  uni.showModal({
    content: '确认任务已经完成了吗？',
    confirmText: '确认并提交',
    cancelText: '取消',
    success: function (res) {
      if (res.confirm) {
        loadingShow.value = true
        post(`/solution-ppm/api/v2/built-in-system-ppm/dashboard/task/${id.value}/standard_info/submit`, {
          "attachment": JSON.stringify(taskDetail.value.attachment),
          sopList: sopList.value,
          form: [...finishStandardList.value, ...taskDetail.value.assessorStandardList.map(item => ({
            ...item,
            selected: true
          }))],
          taskId: taskDetail.value.taskId
        }).then(res => {
          if (res.code !== 200) {
            toast.value.show({
              title: res.message,
              type: 'error',
            });
            return;
          }
          toast.value.show({
            title: '操作完成',
            type: 'success',
          });
          setTimeout(() => {
            getTaskDetail();

          }, 1000);
        }).finally(() => {
          completeDisabled.value = false;
          loadingShow.value = false
        })
      } else if (res.cancel) {
        completeDisabled.value = false;
      }
    }
  });
  }else{
    if(taskDetail.value.attachment.length<1){
      toast.value.show({
      title: '请上传附件',
      type: 'error',
    });
    }else{
      loadingShow.value = true
    // 行动项任务完成
    put(`/solution-ppm/api/v2//built-in-system-ppm/action_task/${actionTaskId.value}/complete`, {
    ppmEnclosureInfoList: taskDetail.attachment,
    taskId: actionTaskId.value
  }).then(data => {
    if (data.code === 200) {
      toast.value.show({
      title: '操作成功!',
      type: 'success',
    });
      actionState.fileList = []
    } else {
      toast.value.show({
      title: data.message,
      type: 'error',
    });
      
    }
  }).finally(()=>{
    loadingShow.value = false
  })
    }

  }

}
let handle_vid_rg51oa99zm_uploadFailed = async (...params) => {
  // 上传失败
  const [errorMsg = ''] = params;
  toast.value.show({
    title: errorMsg,
    type: 'error',
  });
};

let handle_vid_rg51oa99zm_uploadSuccess = async (...params) => {
  if(!isActionTask.value){
    post(`/solution-ppm/api/v2/built-in-system-ppm/dashboard/task/${id.value}/attachment/submit`, { "attachment": JSON.stringify(taskDetail.value.attachment) }).then(res => {
    if (res.code !== 200) {
      toast.value.show({
        title: res.message,
        type: 'error',
      });

      return;
    }
    // 上传成功
    toast.value.show({
      title: '操作成功!',
      type: 'success',
    });
  })
  }else{
    post(`/solution-ppm/api/v2/built-in-system-ppm/dashboard/action_task/${actionTaskId.value}/attachment/submit`, { "attachment": JSON.stringify(taskDetail.value.attachment) }).then(res => {
    if (res.code !== 200) {
      toast.value.show({
        title: res.message,
        type: 'error',
      });

      return;
    }
    // 上传成功
    toast.value.show({
      title: '操作成功!',
      type: 'success',
    });
  })
  }
};
const activeClass = (text) => {
  return {
    time: text.startsWith('倒计时'),
    delay: text.startsWith('延期'),
    add: !text.startsWith('倒计时') && text.indexOf('+') !== -1,
    minus: !text.startsWith('倒计时') && text.indexOf('-') !== -1,
  }
}
const hasTime = computed((text) => {
  return (text) => {
    if (!text.startsWith('倒计时')) {
      return true;
    }
    return text.indexOf('-') === -1
  }
})


//冯腾飞加
function handleStart() {
 if(!isActionTask.value){
  post(`/solution-ppm/api/v2/built-in-system-ppm/task/faq/study/search`, { taskId: taskDetail.value.taskId }).then(
    res => {
      if (res.data.taskQuestionFinishStandardList?.length || res.data.taskQuestionSopList?.length) {
        handleRedirect(`/pages/Page3000000331/Page3000000331?id=${taskDetail.value.taskId}`)
      } else {
        uni.showToast({
          title: '已开始该任务，请及时完成任务',
          icon: 'success'
        });
        getTaskDetail()
      }
    }
  )
 }else{
  // 行动项任务开始
  put(`/solution-ppm/api/v2/built-in-system-ppm/action_task/${actionTaskId.value}/start`).then(data => {
        if (data.code === 200) {
          uni.showToast({
          title: '已开始该任务，请及时完成任务',
          icon: 'success'
        });
        getTaskDetail()
        } else {
          uni.showToast({
          title: data.message,
          icon: 'error'
        });
        }
      })
 }

}
//冯腾飞加
function checkAllSelected(content) {
  for (let i = 0; i < content.length; i++) {
    if (!content[i].selected) {
      return false; // 只要有一个 selected 不为 true，就返回 false
    }
  }
  return true; // 如果所有的 selected 都为 true，返回 true
}
function handleSubmitSop() {
  if(!isActionTask.value){
    const params = {
    form: [],
    sopList: sopList.value,
    taskId: taskDetail.value.taskId
  }
  params.form = [...finishStandardList.value]
  post('/solution-ppm/api/v2/built-in-system-ppm/delivery_task/save_standard_sop', params).then(() => {
    toast.value.show({
      title: '保存成功!',
      type: 'success',
    });
    setTimeout(() => {
      handleRedirect(`/pages/Page3000000251/Page3000000251?`)
    }, 500)
  })
  }else{

  }
}
</script>
<style lang="less" scoped>
.page_root {
  min-height: 100%;
  box-sizing: border-box;
}


.page_root {
  min-height: 100%;
  box-sizing: border-box;
  background: #e1effd;
}

.container {
  padding: 30rpx;
  height: 100vh;
}

.container .complete {
  width: 100%;
  height: 52px;
  position: absolute;
  bottom: 0;
  left: 0;
  border-radius: 0;
  z-index: 20;
  font-size: 20px;
  font-weight: bold;
}

.container .content .item .title {
  width: 100%;
  height: 32px;
  padding-left: 24rpx;
  background-image: linear-gradient(90deg, #CDE8FD 0%, rgba(205, 232, 253, 0.00) 100%);
  font-size: 32rpx;
  color: #262626;
  letter-spacing: 0;
  font-weight: 600;
  line-height: 32px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  word-break: keep-all;
  border-radius: 15px 0 0 0;
}

.container .content .item .article .class1 {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 6px;
  padding: 0 5px;
}

.container .content .item .article .class2 {
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.80) 0%, rgba(255, 255, 255, 0.90) 50%, rgba(255, 255, 255, 0.80) 100%);
  border: 1px solid #FFFFFF;
  box-shadow: 0 2px 10px 0 #CFE7FF;
  border-radius: 9px;
  font-weight: bold;
  text-align: center;
  color: #2CD8F9;
  padding: 0px 14rpx;
}

.container .content .item .article .mr10 {
  margin-right: 20rpx;
}

.container .content .item .article .class3 {
  width: 62px;
  text-align: right;
  background-image: linear-gradient(270deg, rgba(205, 232, 253, 0.00) 0%, #CDE8FD 100%);
  border-radius: 10px;
  color: #595959;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container .content .item .article .title1 {
  font-size: 26rpx;
  color: #595959;
}

.container .content .item .article .value1 {
  font-size: 26rpx;
  color: #262626;
  font-weight: 600;
}

.container .content .item .article .row {
  margin-bottom: 7px;
  margin-left: 3px;
}

.container .content .item .article .no-padding .title1 {
  padding: 0 !important;
}

.container .content .item .article {
  padding: 14rpx;

}

.container .content .item .u-form .u-form-item {
  padding: 0;
}

:deep(.container .content .item .u-form .u-form-item--left) {
  padding-left: 0px;
}

.container .content .item .u-form {
  margin: -10rpx 16rpx 0 16rpx;
}

:deep(.u-form-item--left__content__label) {
  margin-bottom: -10rpx;
  color: #595959;
}

.container .content {
  background: #fff;
  border-radius: 15px;
  height: 92%;
  overflow: auto;
  border: 1px solid #fff;

}

:deep(.u-toast .u-text) {
  text-align: left;
}

:deep(.u-checkbox) {
  width: 100% !important;
  align-items: flex-start;
}

:deep(.u-checkbox__label) {
  font-size: 28rpx;
  color: #262626;
}

:deep(.assessor .u-form-item--right__content__slot) {
  flex-direction: column;
  font-size: 14px;
  line-height: 23px;
  color: #262626;
}

:deep(.u-checkbox__icon-wrap--square) {
  margin-top: 12rpx;
  width: 28rpx;
  height: 28rpx;
}

.container .content .mark {
  font-size: 24rpx;
  color: #008bff;
  padding: 2rpx 8rpx;
  border: 2rpx solid #008bff;
  border-radius: 14rpx;
}

.container .content .item .label-wrapper {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  margin: 20rpx 0 4rpx 16rpx;
}

.container .content .item .label {
  font-size: 24rpx;
  padding: 0 8rpx;
  margin-right: 8rpx;
  border-radius: 2rpx;
}

.container .content .item .add {
  background: rgba(82, 196, 26, .1);
  color: rgba(82, 196, 26, 1);
}

.container .content .item .minus,
.container .content .item .delay {
  background: rgba(245, 34, 45, .1);
  color: rgba(245, 34, 45, 1);
}

.container .content .item .time {
  background: rgba(255, 123, 0, .1);
  color: rgba(255, 123, 0, 1);
}

.container .divider {
  width: 100%;
  height: 2rpx;
  background: #EBEBEB;
  margin: 16rpx 0;
}

.bottom-btn {
  display: flex;
  width: 100%;
  height: 52px;
  position: absolute;
  bottom: 0;
  left: 0;
  border-radius: 0;
  z-index: 20;
  font-size: 20px;
  font-weight: bold;
}

.bc-btn,
.wc-btn {
  width: 45%;
}

/*
        标志
        */

.first,
.lcb,
.finally,
.gjlj {
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.80) 0%, rgba(255, 255, 255, 0.90) 50%, rgba(255, 255, 255, 0.80) 100%);
  border: 1px solid #FFFFFF;
  box-shadow: 0 2px 10px 0 #CFE7FF;
  border-radius: 9px;
  font-weight: bold;
  text-align: center;
  color: #2CD8F9;
  padding: 0 16rpx;
}

.first {
  color: #00B4EC;
}

.lcb {
  color: #3875FF;
}

.finally {
  color: #EA00FF;
}

.gjlj {
  color: #FF9846;
}

.container .content .item .minus[data-v-1fad1d5b],
.container .content .item .delay {
  margin-bottom: 3px;
}

.container .content .item .add {
  margin-bottom: 3px;
}
</style>
